﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TestOnlineProject.Models.Entities;

namespace TestOnlineProject.Controllers
{
    public class BaseController : Controller
    {
        public User CurrentUser
        {
            get
            {
                if (this.Session[SessionKey.CurrentUser] != null)
                {
                    return (User)this.Session[SessionKey.CurrentUser];
                }
                return null;
            }
            set
            {
                if (this.Session[SessionKey.CurrentUser] == null)
                {
                    this.Session.Add(SessionKey.CurrentUser, value);
                }
                else
                {
                    this.Session[SessionKey.CurrentUser] = value;
                }
            }
        }
    }

    internal static class SessionKey
    {
        private static String _CurrentUser = "CurrentUser";
        public static String CurrentUser
        {
            get{
                return _CurrentUser;
            }
        }
    }
}
